unit Con_ItemPedCompra;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids, dbtables, db,
  TFlatButtonUnit;

type
  TFrmCon_ItemPedCompra = class(TFrmConsulta)
    EdtPed_item: TEdit;
    Label1: TLabel;
    DbgItem: TDBGrid;
    procedure EdtPed_itemKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    ped_item: string;
    numero: string;
    codigo: string;
  end;

var
  FrmCon_ItemPedCompra: TFrmCon_ItemPedCompra;

implementation

uses ClsItemPedCompra, Dm;

var
  ItemPedCompra: TItemPedCompra;
  tq: TQuery;
  tds: TDataSource;
{$R *.DFM}

procedure TFrmCon_ItemPedCompra.EdtPed_itemKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    EdtPed_item.setfocus;
  end;
end;

procedure TFrmCon_ItemPedCompra.FazConsulta;
begin
  ItemPedCompra.Consultar(tq, numero, codigo);
  tq.open;
  DbgItem.DataSource := tds;
  DbgItem.Refresh;
end;

procedure TFrmCon_ItemPedCompra.FormCreate(Sender: TObject);
begin
  inherited;
  ItemPedCompra := TItemPedCompra.create;
end;

procedure TFrmCon_ItemPedCompra.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  ItemPedCompra.free;
end;

procedure TFrmCon_ItemPedCompra.FormActivate(Sender: TObject);
begin
  inherited;
  tds := TDataSource.create(FrmCon_ItemPedCompra);
  tds.name := 'dsItemPedCompra';
  tq := Tquery.create(FrmCon_ItemPedCompra);
  tq.databasename := dm.dmint.db.databasename;
  tq.name := 'qItemPedcompra';
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  EdtPed_item.setfocus;
end;

procedure TFrmCon_ItemPedCompra.BtnFecharClick(Sender: TObject);
begin
  inherited;
  ped_item := tq.fieldbyname('pedc_item').AsString;
  tds.free;
  tq.Free;
end;

end.
